package cn.yyh.user.utils;

import cn.yyh.user.pojo.po.LoginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author 杨永航
 * @version 1.0
 * @Title: TokenToRedis
 * @Package: cn.yyh.user.utils
 * @date 2021/7/4
 */
public class TokenUtil {

    public static Map<String,Object> token2Redis(RedisTemplate redisTemplate,LoginInfo value,long timeout) {
        String token = UUID.randomUUID().toString();
        // 5.把token作为k,当前对象loginInfo作为v设置到redis,设置过期时间30分钟
        redisTemplate.opsForValue().set(token,value,timeout, TimeUnit.MINUTES);
        // 6.把token和loginInfo设置到map中,并返回给前端
        value.setPassword(null);
        value.setSalt(null);
        Map<String, Object> m = new HashMap<>();
        m.put("token",token);
        m.put("loginInfo",value);
        return m;
    }
}
